const routes = [
    {
        path: '/',
        name: "index",
        component: indexPage,
        children: [
            {
                path: '/details',
                name: "details",
                component: detailsPage,
                children: [
                    {
                        path: '/details/peopleList',
                        name: "peopleList",
                        component: peopleListWrap
                    },
                ]
            },
            {
                path: '/news',
                name: "news",
                component: newsDetails,
                children: [
                    {
                        path: '/news/newsAdd',
                        name: "newsAdd",
                        component: addNewsListWrap
                    },
                    {
                        path: '/news/newsDetails_info',
                        name: "newsDetails_info",
                        component: infoDetailPage
                    },
                    {
                        path: '/news/peopleList',
                        name: "newsPeopleList",
                        component: peopleListWrap
                    },
                ]
            },
        ]
    },
];

const router = new VueRouter({
    routes
});

const store = new Vuex.Store({
    state: {
        showFlag: 0,
        headerAnimate: "",
        title: "",
        headerType: 0,
        peopleList: false,
        loadingShow: false,
    },
    mutations: {
        _showFlag(state, val){
            state.showFlag = val;
        },
        _headerAnimate(state, val){
            state.headerAnimate = val;
        },
        _title(state, val){
            state.title = val;
        },
        _headerType(state, val){
            state.headerType = val;
        },
        _peopleList(state, val){
            state.peopleList = val;
        },
        _loadingShow(state, val){
            state.loadingShow = val;
        },
    },
    getters: {
        //改变头部文字
        showFlag_get(state){
            state.title = getHeader.init(state.showFlag);
            return state.showFlag;
        },
        headerAnimate_get(state){
            return state.headerAnimate;
        }
    },
    actions: {
        showFlag_action(context, val){
            context.commit("_showFlag", val);
        },
        headerAnimate_action(context, val){
            if (val) {
                context.commit("_headerAnimate", "header-back");
            } else {
                context.commit("_headerAnimate", "header-forward");
            }
            setTimeout(() => {
                context.commit("_headerAnimate", "");
            }, 500);
        }
    }
});

const APP = new Vue({
    router,
    store
});

function goBack(index) {
    if (isPush.flag && (store.state.showFlag.toString() === "12" || store.state.showFlag.toString() === "2")) {
        vrvInit.closeWindow();
        return;
    }
    index = index || -1;
    store.dispatch("headerAnimate_action", 1);
    window.history.go(index);
}

function headerTitleChange(v) {
    store.dispatch("headerAnimate_action", 0);
    store.dispatch("showFlag_action", v);
}

function goName(name, flag) {
    flag && headerTitleChange(flag);
    router.push({name})
}

function goPathWithParams(path, flag) {
    flag && headerTitleChange(flag);
    router.push({path})
}